<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 系统管理 <span class="c-gray en">&gt;</span> 角色管理<span class="c-gray en">&gt;</span> 设置角色数据权限</nav>
	<div id="sectionContent" class="Hui-article">
		<article class="cl pd-20">
			<table class="table">
				<tr>
					<td width="200" class="va-t">
						<div class="cl pd-5 bg-1 bk-gray">
								<span class="l">平台权限导航</span>
						</div>
						<ul id="systemMenus" class="ztree"></ul>
					</td>
					<td class="va-t">
						<div class="form form-horizontal" id="form-admin-add">
								<div class="mt-20">
									<div class="Huialert Huialert-success">{{title}}[数据权限]</div>
									<input type="hidden" id="platform"/>
										<table class="table table-border table-bordered" v-for="(row,index) in result">
											<tr>
												<td class="va-m" width="130px">{{(row,index).moduleName}}</td>
												<td class="va-t" colspan="3">
														<span v-for="(dataAuth,index) in (row,index).dataAuths">
																<label><input type="checkbox" name="dataAuth" checked="{{(dataAuth,index).hasRole}}" value="{{(dataAuth,index).id}}"/>{{(dataAuth,index).name}}</label>
														</span>
												</td>
											</tr>
										</table>
								</div>
								<div class="mt-20">
									<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
										<input class="btn btn-primary" type="button" v-on:click="saveData()" value="&nbsp;&nbsp;提交&nbsp;&nbsp;" style="margin-right:30px;">
										<input class="btn" type="button" onclick="javascript:history.go(-1)" value="&nbsp;&nbsp;取消&nbsp;&nbsp;">
									</div>
								</div>
							</div>
					</td>
		</article>
	</div>
<script>
      new Vue({
          el:'#sectionContent',
          http: authorization(),
          data:{
							parentId:0,
							title:'',
              result:[]
          },
          created:function(){
							this.$http.get('/restful/base/v1.0/commmon/platform/dauths').then((response) => {
									var setting = {
											data: {
													simpleData: {
															enable: true,
															pIdKey: "pid"
													}
											},
											callback: {
												onClick: this.zTreeOnClick
											}
									};
									var menus = new Array();
									var platform = null;
									responseObj(response).data.forEach(function(data){
											var menu = new Object();
											menu.id = data.code;
											menu.name = data.name;
											menus.push(menu);
											if(null == platform) {
												platform = data;
											}
									});
									$.fn.zTree.init($("#systemMenus"), setting, menus);

									this.$http.get('/restful/base/v1.0/auth/role/data_auth/'+getQueryString('id')+"/"+platform.code).then((response) => {
											this.title = platform.name;
											$('#platform').val(platform.code);
			                this.result = responseObj(response).data;
			            }).catch(function(response) {
			                alert(errorMsg(response));
			            });
							}).catch(function(response) {
									alert(errorMsg(response));
							});
          },
          methods:{
						zTreeOnClick:function(event, treeId, treeNode){
							 this.title = treeNode.name;
							 $('#platform').val(treeNode.id);
							 this.$http.get('/restful/base/v1.0/auth/role/data_auth/'+getQueryString('id')+"/"+treeNode.id).then((response) => {
									 this.result = responseObj(response).data;
							 }).catch(function(response) {
									 alert(errorMsg(response));
							 });
						},
						backToList:function(){
                window.parent.location.href="#!view/system/role/role-list.html?"+Math.random();
            },
						saveData:function(){
							var chk_value =[];
							$('input[name="dataAuth"]:checked').each(function(){
							 	chk_value.push($(this).val());
							});

							this.$http.post('/restful/base/v1.0/auth/setting/role/data_auth?roleId='+getQueryString('id')+"&dataAuthIds="+chk_value+"&platform="+$('#platform').val()).then((response) => {
									this.backToList();
							}).catch(function(response) {
									alert(errorMsg(response));
							});
						}
          }
      });
  </script>
